package com.bafa.services;

import com.bafa.jdbc.DBAccess;
import com.bafa.jdbc.QueryObject;
import com.bafa.jdbc.UpdateObject;

public class MatchTableServices {

	static void confirmResult(DBAccess db, int matchId){
		QueryObject query = new QueryObject("matches");
		query.addWhereAndField("ID",new Integer(matchId).toString());
		UpdateObject updateObj = new UpdateObject();
		updateObj.addField("AddedA",new Integer(1));
		updateObj.addField("AddedB",new Integer(1));
		
		try{
			db.update(query,updateObj);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	static void updateMatch(DBAccess db,int matchId, int goalsA, int goalsB,boolean walkover, boolean teamA){
			QueryObject queryObj2 = new QueryObject("matches");
			queryObj2.addWhereAndField("ID",new Integer(matchId).toString());
			
			UpdateObject updateObj = new UpdateObject();
			updateObj.addField("GoalsA",new Integer(goalsA));
			updateObj.addField("GoalsB",new Integer(goalsB));
			updateObj.addField("Played",new Integer(1));
			updateObj.addField("Blocked",new Integer(0));
			if(teamA)updateObj.addField("AddedA",new Integer(1));
			else updateObj.addField("AddedB",new Integer(1));
			if(walkover)updateObj.addField("Walkover",new Integer(1));
	//		 update the matches table
			try{
				db.update(queryObj2,updateObj);
			}catch(Exception e){
				e.printStackTrace();
			}
		}

}
